{include file="public/header" /} {include file="public/lefter" /}
{css href="__PLUG__/bootstrap-table/bootstrap-table.css" /}
{css href="__PUBLIC__/static/css/table.css" /}
<div class="box-a">
	<div class="nav-c">
		<span class="glyphicon glyphicon-tag">&nbsp;</span><span>文章管理</span>
	</div>
	<box class="box-b">
		<div class="divs">
			<div id="toolbar">
				<button type="button" id="dellist" class="btn btn-danger"><span class="glyphicon glyphicon-trash"> </span>删除</button>
				<a role="button" href="{:URL('/admin/article/add')}" type="button" class="btn btn-primary">撰写文章</a>
				<a role="button" href="{:URL('/admin/article/sorts')}" type="button" class="btn btn-warning">分类管理</a>
			</div>
			<div class="table-responsive" data-show-refresh="true">
				<table id="table">
				</table>
			</div>
		</div>
	</box>
</div>
<!--<a class="btn btn-xs btn-success" href="/index.php/admin/netset/bak/tp/dowonload/name/20160517154306.sql.html">下载</a>-->


{include file="public/flooter" /}
{js href="__PLUG__/bootstrap-table/bootstrap-table.js" /}
{js href="__PLUG__/bootstrap-table/locale/bootstrap-table-zh-CN.js" /}
{js href="__PLUG__/bootstrap-table/extensions/export/bootstrap-table-export.js" /}
{js href="__PLUG__/bootstrap-table/extensions/export/tableExport.js" /}



<script type="text/javascript">
    var $table = $('#table');
	$(document).ready(function() {		
		$table.bootstrapTable({
			classes: 'table table-hover',
			paginationPreText: '上一页',
			paginationNextText: '下一页',
			pagination: true,
			search: true,
			searchOnEnterKey: true,
			showColumns: true,
			showRefresh: true,
			showToggle: true,
			showPaginationSwitch: true,
			idField: 'uid',
			showexport: true,
			uniqueId: 'uid',
			toolbar: '#toolbar',			
			sidePagination: 'server',
			url: '__ROOT__/admin/article/articlelist',
			columns: [
			{
				checkbox:true,				
				align: 'center'
			},{
				field: 'id',
				title: 'ID',
				align: 'center'
			}, {
				field: 'title',
				title: '标题',
				editable: true,
				align: 'center'
			},{
				field: 'sort',
				title: '所属分类',
				editable: true,
				align: 'center'
			},{
				field: 'add_time',
				title: '创建时间',
				editable: true,
				align: 'center'
			},{
				field: 'count',
				title: '访问量',
				editable: true,
				align: 'center'
			},{
				field: 'status',
				title: '状态',
				editable: true,
				align: 'center'
			},{
				field: 'op',
				title: '操作',				
				editable: true,
				formatter: oper,
				align: 'center'
			},],
		});

		function oper(value, row, index) {			
			
			var arid = row.id;
			var status=row.status;			
			var opdata = '<a href="__ROOT__/admin/article/edit?aid=' + arid +'" role="button" style="margin-right: 5px" type="button" class="btn btn-xs btn-default btn-icon"><i class="fa fa-cog"></i></a>';
			    if (status!='<span style="color:#CC0000">停用</span>') {
			    	opdata += '<div style="margin-right: 5px" type="button" title="停用" class="btn-on btn btn-xs" onclick="arset(\'stop\',\'' + arid + '\')"><i class="fa fa-toggle-on"></i></div>';			    	
			    } else{
			    	opdata += '<div style="margin-right: 5px" type="button" title="启用" class="btn btn-xs btn-off" onclick="arset(\'start\',\'' + arid + '\')"><i class="fa fa-toggle-off"></i></div>';			    	
			    }
				opdata += '<div style="margin-right: 5px" type="button" class="btn btn-xs btn-del" onclick="arset(\'del\',\'' + arid + '\')"><i class="fa fa-trash"></i></div>';			    	

			
			return opdata;
		}

		function vid(value, row, index) {
			//var row=index;
			return index;
		}
	});

	function arset(sets,arid) {
		var $table = $('#table');
		if(sets=='stop' || sets=='start'){						
			$.get("__ROOT__/admin/article/set", {
				arset: sets,
				arid: arid,
			}, function(response) {
				//$table.bootstrapTable('removeByUniqueId', uid);//
				$table.bootstrapTable('refresh', {silent: true});
				if (response) {					
					layer.msg(response);
				} else {
                    layer.msg('操作失败！请重试！');					
				}
			});
			
		}
		if(sets=='del'){
			layer.confirm('<i style="color:#FF6633" class="icon-warning-sign icon-2x"></i> 是否删除?', {
                btn: ['确定','取消'] //按钮
            }, function(){
            	delarticle(arid);           
            }, function(){           	
            });
		}
		
			
		
	}
	$("#dellist").click(function(){
        var act=$table.bootstrapTable('getSelections');
        if(act==false){
       	  layer.msg('请选择要删除的列表'); 
        }else{
        	layer.confirm('是否批量删除选中项？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                delar(act);
            }, function(){
                
            });
       	
        }
       
      
    });
    function delar(act){
    	$.get("__ROOT__/admin/article/set", {
			arset: 'dellist',
			data: act,
		}, function(response) {
				//$table.bootstrapTable('removeByUniqueId', uid);//
			$table.bootstrapTable('refresh', {silent: true});
			if (response) {					
				layer.alert(response);
			} else {
                layer.alert('操作失败！请重试！');					
			}
		});
    }
    function delarticle(arid){
		var $table = $('#table');
		$.get("__ROOT__/admin/article/set", {
			arset: 'del',
			arid: arid,
		}, function(response) {
			$table.bootstrapTable('refresh', {silent: true});
			if (response) {					
				layer.alert(response);
			} else {
                layer.alert('操作失败！请重试！');					
			}
		});
	}
    function retable(index, layero){
    	$table.bootstrapTable('refresh', {silent: true});
    }
</script>

